package org.md.budzik.problems;

import java.math.BigInteger;
import java.util.Map;

/**
 * Abstrakt działania dwuargumentowego.
 * @author Wiezzel
 *
 */
public abstract class TwoArgOp extends Expression {
	
	protected Expression firstArg;
	protected Expression secondArg;

	protected abstract BigInteger computeOperation(BigInteger x, BigInteger y) throws ParseException;
	
	protected abstract String operationSymbol();

	public String toString() {
		return firstArg.toString() + " " + secondArg.toString() + " " + operationSymbol();
	}
	
	public BigInteger value(Map<String,Integer> variables) throws ParseException {
//		System.out.println(this + " = " + computeOperation(firstArg.value(variables), secondArg.value(variables)));
		return computeOperation(firstArg.value(variables), secondArg.value(variables));
	}
	
	public TwoArgOp(Expression ex2, Expression ex1) {
		this.firstArg = ex1;
		this.secondArg = ex2;
	}
	
}